import {v4 as uuidv4 } from "uuid";
import RootElement from "./rootElement";

interface Element {
    render(): any;
    uuid: string;
}

interface StatusElement <T> extends Element{
    status: T;
}



interface MyCompStatus {
    stat1: string;
}
class MyComp implements StatusElement<MyCompStatus>{
    uuid: string = uuidv4();

    status: MyCompStatus = {
        stat1: "asdf"
    };
    //asdf: string = "";

    constructor(){
        //super();
        //this.innerHTML = this.gHTML();
    }

    render(): any{
        console.log(this);
        return(
            <RootElement className="myComp" uuid={this.uuid}>
                MyComp
                {this.status.stat1}
            </RootElement>
        );
    }
}



//let myComp = new MyComp();
//export default myComp;
export default function MyCompJSX(props: any){
    let comp = new MyComp();
    if(props != null && props !== undefined){
        for(var propName in props as any){
            //console.log(propName);
            if(propName != "rootElementProps"){
                if((comp.status as any)[propName] !== undefined){   // 若元素中定义了于props中同名的字段
                    (comp.status as any)[propName] = props[propName];
                    console.log("WARN: Assigning defined props name=" + propName + ", value=" + props[propName] + " to comp.");
                } else {                                            // 若元素中未定义于props中同名的字段
                    console.log("WARN: Assigning undefined props name=" + propName + ", value=" + props[propName] + " to comp.");
                    (comp.status as any)[propName] = props[propName];
                }
            }
        }
    }
    //console.log(comp.render()[0])

    let rootElementProps = props["rootElementProps"];
    if(rootElementProps !== undefined){
        $(() => {
            let rootElement = (".rootElementProps, [uuid=" + comp.uuid + "]");
            
        });
        for(var propName in rootElementProps){
            console.log("WARN: Transferring rootElementProp name=" + propName + ", value=" + rootElementProps[propName] + " to comp.");
        }
    }
    return comp.render();
}